import BirdControl from "./BirdControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class BgControl extends cc.Component {

    // 速度
    @property
    speed: number = 4;

    // 宽度
    @property
    width: number = 288;

    @property(BirdControl)
    bird: BirdControl = null;

    start() {
        // 开启监听
        for (let bg of this.node.children) {
            bg.on(cc.Node.EventType.MOUSE_DOWN, () => {
               this.bird.fly();
            });
        }
    }

    update(dt) {
        // 移动
        for (let bg of this.node.children) {
            bg.x -= this.speed * dt;
            // 如果背景超出屏幕
            if (bg.x < -this.width) {
                bg.x += this.width * 2;
            }
        }
    }
}
